<extend name="./public/frame.html"/>
<block name="content">
	<blockquote class="layui-elem-quote search">


		<div class="layui-inline">
			<input type="text" lay-verify="required|title" required placeholder="请输入手机号" class="layui-input" id="driver_phone" style="width: 120px;">
		</div>

		<br/><br/>
		<div class="layui-inline">
			<button class="layui-btn" data-type="search">搜索</button>

		</div>
	</blockquote>
	<table class="layui-table" lay-data="{width:'auto', height:'auto', url:'{:url('InterRoute/index')}', page: true, limit: 10, id:'InterRoute'}" lay-filter="InterRoute">
		<thead>
			<tr>
				<th lay-data="{field:'route_id', width:70,fixed: true, sort: true,align:'center',fixed: true}">ID</th>
				<th lay-data="{field:'route_start_city_name', width:90,align:'center'}">出发地</th>
				<th lay-data="{field:'route_end_city_name', width:90,align:'center'}">目的地</th>
				<th lay-data="{field:'driver_name', width:90,align:'center'}">司机姓名</th>
				<th lay-data="{field:'driver_phone', width:120,align:'center'}">手机号码</th>
				<th lay-data="{field:'their_name', width:140,align:'center'}">所属运力</th>
				<th lay-data="{field:'route_price', width:100,align:'center'}">路线价格(元)
				<th lay-data="{field:'route_time', width:100,align:'center'}">路线时间
				<th lay-data="{field:'route_status_name', width:100,align:'center'}">路线状态</th>
				<th lay-data="{field:'create_time', width:150,align:'center'}">创建时间</th>
				<th lay-data="{fixed:'right', toolbar: '#barDemo', width:540, align:'center'}">操作</th>
			</tr>
		</thead>
	</table>
	<script type="text/html" id="barDemo">
		<a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="detail">查看</a>
       <!-- <a class="layui-btn layui-btn-xs" lay-event="qrcode" style="width: 50px">二维码</a>-->
		<!--<a class="layui-btn layui-btn-xs" lay-event="edit">修改</a>-->

		{{#if(d.route_status==1) { }}
		<a class="layui-btn layui-btn-xs layui-btn-danger " lay-event="forbid">关闭路线</a>
		{{# } else { }}<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="unforbid">开启路线</a>
		{{#}}}
	</script>

	<script type="application/javascript">
		layui.use(['table', 'form', 'laydate'], function () {
			var table = layui.table
				, form = layui.form
				, laydate = layui.laydate;
			lay('.date').each(function(){
				laydate.render({
					elem: this
					,type: 'date'
					,trigger: 'click'
				});
			});
			//监听工具条
			table.on('tool(InterRoute)', function (obj) {
				var data = obj.data;
				var route_id = data.route_id;
				if (obj.event === 'detail') {
					layer.open({
						type: 2,
						title: '路线信息查看',
						shadeClose: true,
						shade: 0.8,
						area: ['100%', '100%'],
						content: '{:url("/admin/InterRoute/detail","route_id=")}' + route_id //iframe的url
					});
				}else if (obj.event === 'forbid') {
                    console.log(data);
                    layer.confirm('确定关闭路线吗?', function (index) {
                        var url = "{:U('forbid_info')}";
                        var act = 'forbid';
                        $.post(url, {'route_id': route_id,'act': act}, function (data) {
                            switch (data.code) {
                                case 1 :
                                    alert(data.msg);
                                    break;
                                default :
                                    alert(data.msg);
                            }
                        }, 'json');
                        layer.close(index);
                        window.location.reload();
                    });
				}
				else if (obj.event === 'unforbid') {
					layer.confirm('确定开启路线吗?', function (index) {
						var url = "{:U('ajax_forbid')}";
						var act = 'unforbid';
						$.post(url, {'route_id': route_id,'act': act}, function (data) {
							switch (data.code) {
								case 1 :
									alert(data.msg);
									break;
								default :
									alert(data.msg);
							}
						}, 'json');
						layer.close(index);
						window.location.reload();
					});
				}else if (obj.event=='edit'){
					layer.open({
						type: 2,
						title: '司机信息查看',
						shadeClose: true,
						shade: 0.8,
						area: ['100%', '100%'],
						content: '{:url("/admin/driver/edit","driver_id=")}' + driver_id //iframe的url
					});
				}
			});
			//搜索
			var $ = layui.jquery, active = {
				search: function () {
					var driver_phone= $('#driver_phone').val();//司机driverId
					table.reload('driver', {
						url: '/admin/InterRoute/index', where: {
							"driver_phone" : driver_phone,
						}
					});
				}

			};
			$('.layui-btn').on('click', function () {
				var type = $(this).data('type');
				active[type] ? active[type].call(this) : '';
			});

		});

	</script>
</block>
